<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset='utf-8'>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<title>轨迹回放</title>
    <link href="<%=basePath%>scripts/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath%>scripts/boot.js" type="text/javascript"></script> 
<style type="text/css">
body {
	margin: 0;
	height: 100%;
	width: 100%;
	position: absolute;
}

#mapDiv {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
}

#tip {
	height: 90px;
	background-color: #fff;
	padding-left: 10px;
	padding-right: 10px;
	border: 1px solid #4b99cb;
	position: absolute;
	font-size: 12px;
	left: 10px;
	bottom: 10px;
	border-radius: 3px;
	line-height: 45px;
}
#tipTop{
	height: 100px;
	background-color: #fff;
	padding-left: 2px;
	padding-right: 2px;
	border: 1px solid #4b99cb;
	position: absolute;
	font-size: 16px;
	left: 2px;
	top: 2px;
	border-radius: 3px;
}
#tip input[type='button'] {
	height: 26px;
	line-height: 28px;
	outline: none;
	text-align: center;
	padding-left: 5px;
	padding-right: 5px;
	color: #FFF;
	background-color: #0D9BF2;
	border: 0;
	border-radius: 3px;
	margin-top: 8px;
	margin-left: 5px;
	cursor: pointer;
	margin-right: 10px;
}
#tipTop input[type='button'] {
	height: 28px;
	line-height: 28px;
	outline: none;
	text-align: center;
	padding-left: 5px;
	padding-right: 5px;
	color: #FFF;
	background-color: #0D9BF2;
	border: 0;
	border-radius: 3px;
	margin-top: 8px;
	margin-left: 5px;
	cursor: pointer;
	margin-right: 10px;
}
</style>
</head>
<body>
	<div id="tipTop" style="width: 95%">
	<table style="width:100%">
		<tr>
			<td align="center" colspan="2"  style="width:70%">
				<div class="ui-field-contain">
					<select name="vehicle_list" id="vehicle_list" onchange="">
					<option value="0">——请选择车辆——</option>
					</select>	
				</div>
			</td>
			<td align="center" style="width:30%">
				<input type="button" value="查询" onclick="Search()">
			</td>
		</tr>
		<tr>
			<td align="center"  style="width:30%">
				<b>开始日期</b>	
			</td>
			<td align="center" colspan="2"  style="width:70%">
				<input id="ksrq" class="mini-datepicker" style="width: 90%" format="yyyy-MM-dd HH:mm:ss" timeFormat="HH:mm:ss" value='new Date(Date.parse(GetDay().replace(/-/g,"/")))' showTime="true" required="true"  ondrawdate="onDrawDate" showOkButton="false" showClearButton="false"/>
			</td>
		</tr>
		<tr>
			<td align="center"  style="width:30%"> 
				<b>结束日期</b>
			</td>
			<td align="center" colspan="2"  style="width:70%">
					<input id="jsrq" class="mini-datepicker" style="width: 90%" format="yyyy-MM-dd HH:mm:ss" timeFormat="HH:mm:ss" value="new Date()" required="true" showTime="true"  ondrawdate="onDrawDate"  showOkButton="false" showClearButton="false" />
			</td>
		</tr>
	</table>
	</div>
	<iframe src='' frameborder='no' id="iframemain" scrolling='auto' style="width: 99%;height: 99%" allowtransparency='true'></iframe>
	<script type="text/javascript">
	 function getUrl(name) {
		    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		    var r = window.location.search.substr(1).match(reg);
		    if (r != null) return unescape(r[2]); return null;
		    }
	$(document).ready(function() {
   		$.ajax({
			async: false,
			type : "post",
			url : "fleet/selectVehicleAll.do",
			//url : "http://LOCALHOST:8080/RMSAPP/jsp/selectVehicleByUser.jsp?userId=13",
			datatype: "JSON",
			success : function(data){
				var list = eval("(" + data + ")");
				var length=list.length;
				for(var i=0;i<length;i++){
					//var option = new Option(list[i].carname,list[i].vin);
					//document.getElementById("vehicle_list").options[i] = option;
					 $("#vehicle_list").append($("<option value=\""+list[i].vehicleid+"\">"+list[i].vehiclename+"</option>")); 
				}		
			},
			error:function(){
	     		mini.alert("error");
	  		}
		});
	 });
	mini.parse();
	
	var vehicleid = mini.get("vehicle_list");
	var ksrqq = mini.get("ksrq");
	var jsrqq = mini.get("jsrq");

	function DateDiff(d1,d2){
	    var day = 24 * 60 * 60 *1000;
	try{    
	        var dateArr = d1.split("-");
	   var checkDate = new Date();
	        checkDate.setFullYear(dateArr[0], dateArr[1]-1, dateArr[2]);
	   var checkTime = checkDate.getTime();
	  
	   var dateArr2 = d2.split("-");
	   var checkDate2 = new Date();
	        checkDate2.setFullYear(dateArr2[0], dateArr2[1]-1, dateArr2[2]);
	   var checkTime2 = checkDate2.getTime();
	    
	   var cha = (checkTime - checkTime2)/day;  
	        return cha;
	    }catch(e){
	   return false;
	}
	}
	function Search(){
		var id=$("#vehicle_list").children('option:selected').val();
		var ksrqdate = ksrqq.getValue();
		var jsrqdate = jsrqq.getValue();
		if(ksrqdate==null||ksrqdate==""||jsrqdate==null||jsrqdate==""){
			return;
		}
		if(ksrqdate>jsrqdate){
			mini.alert("开始日期不能大于结束日期");
			return;
		}
		var ksyear = ksrqdate.getFullYear();
		var ksmon = ksrqdate.getMonth()+1;
		if(parseInt(ksmon)<10){
			ksmon = "0"+ksmon;
		}
		var ksday = ksrqdate.getDate(); 
		if(parseInt(ksday)<10){
			ksday = "0"+ksday;
		}
		var kshour = ksrqdate.getHours();
		if(parseInt(kshour)<10){
			kshour = "0"+kshour;
		}
		var ksmin = ksrqdate.getMinutes();
		if(parseInt(ksmin)<10){
			ksmin = "0"+ksmin;
		}
		var kssec = ksrqdate.getSeconds();
		if(parseInt(kssec)<10){
			kssec = "0"+kssec;
		}
		
		var jsyear = jsrqdate.getFullYear();
		var jsmon = jsrqdate.getMonth()+1;
		if(parseInt(jsmon)<10){
			jsmon = "0"+jsmon;
		}
		var jsday = jsrqdate.getDate(); 
		if(parseInt(jsday)<10){
			jsday = "0"+jsday;
		}
		var jshour = jsrqdate.getHours();
		if(parseInt(jshour)<10){
			jshour = "0"+jshour;
		}
		var jsmin = jsrqdate.getMinutes();
		if(parseInt(jsmin)<10){
			jsmin = "0"+jsmin;
		}
		var jssec = jsrqdate.getSeconds();
		if(parseInt(jssec)<10){
			jssec = "0"+jssec;
		}
		var ksrq=ksyear+"-"+ksmon+"-"+ksday+" "+kshour+":"+ksmin+":"+kssec;
		var jsrq=jsyear+"-"+jsmon+"-"+jsday+" "+jshour+":"+jsmin+":"+jssec;
		var bjksrq = ksyear+"-"+ksmon+"-"+ksday;
		var bjjsrq = jsyear+"-"+jsmon+"-"+jsday;
		var diff = DateDiff(bjksrq,bjjsrq);
		if(diff<-7){
			mini.alert("最大选择时间段为7天");
			return;
		}
		$("#iframemain").attr("src","APP/AppPlayback.jsp?ksrq="+ksrq+"&&jsrq="+jsrq+"&&vehicleid="+id);
	}
		function onDrawDate(e) {
            var date = e.date;
            var d = new Date();

            if (date.getTime() > d.getTime()) {
                e.allowSelect = false;
            }
        }
		function GetDay()
		{
			var   today=new   Date();   
			var   yesterday_milliseconds=today.getTime()-1000*60*60*24;   
			var   yesterday=new   Date();   
			yesterday.setTime(yesterday_milliseconds);   
			
			var strYear=yesterday.getFullYear();
			var strDay=yesterday.getDate();
			var strMonth=yesterday.getMonth()+1;
			if(strMonth<10)
			{
				strMonth="0"+strMonth;
			}
			var strYesterday=strYear+"-"+strMonth+"-"+strDay;
			return strYesterday;
		}
	</script>
</body>
</html>


